{* $Id$ *}
{include_core file="admin/lib/header.html"}
<style type="text/css">
  .list-table tbody tr td .btn{
      font-size: 14px;
  }
</style>
  <div class="page-header border-bottom clearfix">
    <h2 class="left">{$page_title}</h2>
     <a  style="margin-top:5px; display:block; float:right;" data-url="{get_url()}&is_excel=1"  class="btn btn-xs btn-success js_downList export_excel">导出EXCEL</a>
  </div>
  <div class="search-form js_advancedForm">
    <form action="{AnUrl("$page_url")}" method="get" class="js_orderSearchForm">
      <input type="hidden" name="status" value="{$status}">
      <input type="hidden" name="type" value="{$type}">
      <p>
        <label for="" class="search-f-label">订单编号：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[order_code]" value="{$search_filter.order_code}">
      </p>
      <p>
        <label for="" class="search-f-label">合伙人姓名：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[agency_name]" value="{$search_filter.agency_name}">
      </p>
      <p>
        <label for="" class="search-f-label">合伙人手机：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[agency_mobile]" value="{$search_filter.agency_mobile}">
      </p>
      <p>
        <label for="" class="search-f-label">店铺名称：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[store_name]" value="{$search_filter.store_name}">
      </p>
      <p>
        <label for="" class="search-f-label">掌柜手机：</label>
        <input type="text" class="search-f-ipt1" name="search_filter[user_mobile]" value="{$search_filter.user_mobile}">
      </p>
      <p>
      <label for="" class="search-f-label">添加时间：</label>
        <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[start_date_add]" value="{$search_filter.start_date}" id="startDate">
        <span class="search-f-line"></span>
        <input type="text" class="search-f-ipt1 search-f-ipt2" name="search_filter[end_date_add]" value="{$search_filter.end_date}" id="stopDate">
      </p>
      <p><label for="" class="search-f-label"></label><button type="submit" class="btn btn-success btn-xs js_searchBtn">搜索</button></p>
    </form>
  </div>
  <!--start:列表-->
<div class="list-table-filters">
{if $delivery_note_status < 2}
  <p>
    <span class="label label-info">送货单</span>
    <a href='{AnUrl("$page_url?{URLTracker::set("delivery_note_status", -1)}")}' {if URLTracker::val("delivery_note_status") === -1} class="label label-primary" {else} class="label label-default" {/if}>所有</a>
    <a href='{AnUrl("$page_url?{URLTracker::set("delivery_note_status", 0)}")}' {if URLTracker::val("delivery_note_status") === 0} class="label label-primary" {else} class="label label-default" {/if}>未上传</a>
    <a href='{AnUrl("$page_url?{URLTracker::set("delivery_note_status", 1)}")}' {if URLTracker::val("delivery_note_status") === 1} class="label label-primary" {else} class="label label-default" {/if}>待审核</a>
  </p>
{/if}
  <p>
    <span class="label label-info">白条支付</span>
    <a href='{AnUrl("$page_url?{URLTracker::set("is_ious", -1)}")}' {if URLTracker::val("is_ious") === -1} class="label label-primary" {else} class="label label-default" {/if}>所有</a>
    <a href='{AnUrl("$page_url?{URLTracker::set("is_ious", 1)}")}' {if URLTracker::val("is_ious") === 1} class="label label-primary" {else} class="label label-default" {/if}>是</a>
    <a href='{AnUrl("$page_url?{URLTracker::set("is_ious", 0)}")}' {if URLTracker::val("is_ious") === 0} class="label label-primary" {else} class="label label-default" {/if}>否</a>
  </p>
    <p>
        <span class="label label-info">余额支付</span>
        <a href='{AnUrl("$page_url?{URLTracker::set("pay_user_money", -1)}")}' {if URLTracker::val("pay_user_money") === -1} class="label label-primary" {else} class="label label-default" {/if}>所有</a>
        <a href='{AnUrl("$page_url?{URLTracker::set("pay_user_money", 1)}")}' {if URLTracker::val("pay_user_money") === 1} class="label label-primary" {else} class="label label-default" {/if}>是</a>
        <a href='{AnUrl("$page_url?{URLTracker::set("pay_user_money", 0)}")}' {if URLTracker::val("pay_user_money") === 0} class="label label-primary" {else} class="label label-default" {/if}>否</a>
    </p>
    <!--
    <p>
        <span class="label label-info">抱抱币兑换</span>
        <a href='{AnUrl("$page_url?{URLTracker::set("exchange_num", -1)}")}' {if URLTracker::val("exchange_num") === -1} class="label label-primary" {else} class="label label-default" {/if}>所有</a>
        <a href='{AnUrl("$page_url?{URLTracker::set("exchange_num", 1)}")}' {if URLTracker::val("exchange_num") === 1} class="label label-primary" {else} class="label label-default" {/if}>已兑换</a>
        <a href='{AnUrl("$page_url?{URLTracker::set("exchange_num", 0)}")}' {if URLTracker::val("exchange_num") === 0} class="label label-primary" {else} class="label label-default" {/if}>未兑换</a>
    </p>-->
</div>
{include_core file="admin/lib/pager.html"}
  <table class="list-table goods-table">
    {$order_type_list = order_config::$order_type}
    <thead>
      <tr>
        <th style="min-width:100px;">订单编号</th>
        <th style="min-width:200px;">商品</th>
        <th style="width:30px;">单价(元)</th>
        <th style="width:30px;">数量</th>
        <th style="width:30px;">单项总价(元)</th>
        <th style="width:30px;">总量</th>
        <th style="min-width:100px;text-align:right">价格汇总(元)</th>
        <th style="min-width:150px;">掌柜信息</th>
        <th style="width:50px;">状态 &amp; 操作</th>
      </tr>
    </thead>
    <tbody>
      {foreach $order_list as $k => $v}
        {$order_count = count($v.order_relation)}
        {foreach $v.order_relation as $key => $order_relation_info}
          <tr data-id="{$v.id}" id="dataList{$v.id}">
            {if $key == 0}
              <td rowspan="{$order_count}">
                {if $v.is_ious}<span class="label label-success">白</span>{/if}
                {if $v.pay_user_money > 0}<span class="label label-info">余</span>{/if}
                {if $v.exchange_num > 0}<span class="label label-warning">兑</span>{/if}
                {if $v.is_ious || $v.pay_user_money > 0 || $v.exchange_num > 0}<br />{/if}
                订单号：<br />
                {order_helper::order_id_encode($v.id)}<br />
                下单时间：<br />{$v.add_time}<br />
                {if $v.task_user_id}代理下单：{user_helper::display_name($v.task_user_id)}<br />{/if}
                {if $v.task_desc}代理备注：{$v.task_desc}<br />{/if}
                {if $v.transaction_id}
                交易号:<br />{$v.transaction_id}
                {/if}
              </td>
            {/if}
            {$goods_info = goods_helper::get_goods_info($order_relation_info['goods_id'])}
            <td>分类：{_uri('category', $goods_info['category_id'], 'title')}
            <br/>商品名称：{$goods_info['title']}&nbsp;&nbsp;
            <br/>商品简介：{$goods_info['intro']}</td>
            <td><span class="label label-default">{num_keep_two_round($order_relation_info.goods_price)}</span></td>
            <td>{$order_relation_info.goods_num}</td>
            <td><span class="label label-default">{num_keep_two_round($order_relation_info.real_price)}</span></td>
            {if $key == 0}
              <td rowspan="{$order_count}">{$v.goods_num}</td>
              <td rowspan="{$order_count}" style="text-align:right;">
                  <p>
                      <span class="label label-default">总价 {num_keep_two_round($v.price)}</span><br />
                      {if $v.pay_user_money > 0}
                      <span class="label label-warning">余额支付 {num_keep_two_round($v.pay_user_money)}</span><br />
                      {/if}
                      <span class="hr"></span>
                      <span class="label label-info">需付 {num_keep_two_round($v.price - $v.pay_user_money)}</span><br />
                  </p>
                  {if $v.is_ious && $v.delivery_note_status > 1}
                  <p>&nbsp;</p>
                  <p>合伙人 {$v.dealer_info.realname}</p>
                  <p>
                      <span class="label label-{if $v.order_delivery_note.is_return_cash}success">已{else}default">将{/if}返本金 {num_keep_two_round($v.order_delivery_note.return_cash)}</span><br />
                      <span class="label label-{if $v.order_delivery_note.is_return_bbcoin}success">已{else}default">将{/if}返抱币 {intval($v.order_delivery_note.return_bbcoin)}</span><br />
                  </p>
                  {/if}
              </td>
              <td rowspan="{$order_count}">
                {if $v.pay_time != '0000-00-00 00:00:00'}
                <p>支付时间：{$v.pay_time}</p>
                <p>&nbsp;</p>
                {/if}
                {if $v.dealer_info}
                <p>合伙人：{$v.dealer_info.realname}</p>
                <p>合伙人电话：{$v.dealer_info.mobile}</p>
                {/if}
                {if $v.store_user_role == user_config::STORE_MANAGER || $v.store_user_role == user_config::STORE_OWNER}
                  <br>
                  <p>掌柜名：{$v.store_user_info.realname}</p>
                  <p>店铺名：{$v.store_info.title}({$v.store_info.title_branch})</p>
                  <p>掌柜电话：{$v.store_user_info.mobile}</p>
                  <p>店铺地址：
                  <br/>省：{$province_info = area_helper::get_area_info($v.store_info.province_id)}{$province_info['area']}
                  <br/>市：{$city_info = area_helper::get_area_info($v.store_info.city_id)}{$city_info['area']}
                  <br/>区：{$county_info = area_helper::get_area_info($v.store_info.district_id)}{$county_info['area']}
                  <br/>详细地址：{$v.store_info.address}</p>
                  <br/>
                {/if}
                <p>收货人：{$v.store_user_info.realname}</p>
                <p>收货人电话：{$v.store_user_info.mobile}</p>
              </td>
              {$order_progress_list = order_config::$store_progress}
              <td rowspan="{$order_count}">
                {if $v.progress == 1}
                  <span class="label label-warning">{$order_progress_list[$v.progress]}</span>
                {elseif $v.progress == 10}
                  <span class="label label-success">{$order_progress_list[$v.progress]}</span>
                {elseif $v.progress == 15}
                  <span class="label label-default">{$order_progress_list[$v.progress]}</span>
                {else}
                  <span class="label label-info">{$order_progress_list[$v.progress]}</span>
                {/if}
                <!--发票状态-->
                <br/>
                {if $v.make_invoice_status}
                    {$invoice = invoice_helper::get_invoice_by_order_id($v.id)}
                    <span class="label label-success">发票：已开票({invoice_config::$status[$invoice.status]})</span>
                    {if $invoice.actual_price > 0}<span class="label label-success">实开金额:{$invoice.actual_price}</span>{/if}
                {else}
                    <span class="label label-default">发票：未开票</span>
                {/if}
                <!-- 送货单状态 -->
                {$delivery_status = $v.order_delivery_note.status}
                {if isset($delivery_status)}
                  <br/>
                  <span{if $delivery_status != 0} style="display:none"{/if} class="label label-default js-delivery-status js-delivery-status-0">{order_config::$delivery_status[0]}</span>
                  <span{if $delivery_status != 1} style="display:none"{/if} class="label label-warning js-delivery-status js-delivery-status-1">{order_config::$delivery_status[1]}</span>
                  <span{if $delivery_status != 2} style="display:none"{/if} class="label label-info js-delivery-status js-delivery-status-2">{order_config::$delivery_status[2]}</span>
                  <span{if $delivery_status != 3} style="display:none"{/if} class="label label-danger js-delivery-status js-delivery-status-3">{order_config::$delivery_status[3]}</span>
                  <span{if $delivery_status != 4} style="display:none"{/if} class="label label-success js-delivery-status js-delivery-status-4">{order_config::$delivery_status[4]}</span>
                  <span{if $delivery_status != 5} style="display:none"{/if} class="label label-warning js-delivery-status js-delivery-status-5">{order_config::$delivery_status[5]}</span>
                {/if}
                <!-- /送货单状态 -->
                <span class="hr"></span>
                <!-- 送货单操作 -->
                {if $delivery_status == 1}
                  <a{if $delivery_status != 1} style="display:none"{/if} data-id="{$v.id}" data-status="1" href="{AnUrl("order/admin/store_order/ajax_delivery_note_verify")}" class="btn btn-info btn-xs js-delivery-note-btn js-delivery-note-preview-btn"><i class="icon-trash icon-white"></i>送货单预审</a>
                {elseif $delivery_status == 5}
                  <a{if $delivery_status != 5} style="display:none"{/if} data-id="{$v.id}" data-status="5" href="{AnUrl("order/admin/store_order/ajax_delivery_note_verify")}" class="btn btn-info btn-xs js-delivery-note-btn js-delivery-note-verify-btn"><i class="icon-trash icon-white"></i>送货单审核</a>
                {elseif $delivery_status == 2}
                  <a{if $delivery_status != 2} style="display:none"{/if} data-id="{$v.id}" data-status="2" href="{AnUrl("order/admin/store_order/ajax_delivery_note_verify")}" class="btn btn-success btn-xs js-delivery-note-btn js-delivery-note-payback-btn"><i class="icon-trash icon-white"></i>确认回款</a>
                {/if}
                <!-- /送货单操作 -->
              </td>
            {/if}
          </tr>
        {/foreach}
      {foreachelse}
        <tr><td class="txtleft" colspan="10">暂无数据</td></tr>
      {/foreach}
    </tbody>
  </table>
{include_core file="admin/lib/pager.html"}
<!--end:列表-->
<script>
$(function(){
  // 高级搜索时间验证
  $('.js_searchBtn').click(function(e){
    e.preventDefault();
    var thisObj   = $(this);
    var startDate = $.trim($('#startDate').val());
    var stopDate  = $.trim($('#stopDate').val());
    if (startDate > stopDate) {
      showMsg('结束时间应大于等于开始时间');
      return;
    }
    thisObj.closest('form').submit();
  });

  //弹层取消操作
  $('.js_cancel').click(function(){
    $('.float-confirm').hide();
  })

  //触发发货事件
  $('.js_deliveryBtn').click(function(){
    var order_id = $(this).closest('tr').data('id');
    showConfirmDiv($('.js_recommendDiv'), order_id);
  })

  // 同意发货操作
  $('#js_allow').click(function(){
    var express_name = $.trim($('.js_express_name').val());
    var express_no = $.trim($('.js_express_no').val());
    var express_note = $.trim($('.js_express_note').val());
    var id = $('.js_recommendDiv').data('id');

    if (!express_name || express_name == '') {
      showMsg('请填写物流公司名称');
      return false;
    }
    if (!express_no) {
      showMsg('请填写物流单号');
      return false;
    }
    showMask('正在提交中...', 1);
    $.post(
      "{AnUrl('order/admin/shipping')}",
      { express_no:express_no, express_name:express_name, express_note:express_note, id:id },
      function (data){
        if (data.info != 'ok') {
          showMsg(data.info);
        }
        location.href = location.href;
      },
      'json'
    );
  });

  //触发收款按钮事件
  $('.js_payBtn').click(function(){
    var order_id = $(this).closest('tr').data('id');
    showConfirmDiv($('.js_confirm_moneyDiv'), order_id);
  });

  // 确认收款操作
  $('#js_confirm_moneyAllow').click(function(){
    var confirm_money_note = $.trim($('.js_confirm_money_note').val());
    var confirm_money_name = $.trim($('.js_confirm_money_name').val());
    var confirm_money_time = $.trim($('.js_confirm_money_time').val());

    var id = $('.js_confirm_moneyDiv').data('id');
    var params = {};
    params.id = id;

    if (!confirm_money_name) {
        alert('请填写收款人姓名!');
        return;
    }
    params.confirm_money_name = confirm_money_name;

    if (!confirm_money_time) {
        alert('请填写收款时间!');
        return;
    }
    params.confirm_money_time = confirm_money_time;

    if (confirm_money_note) {
        params.confirm_money_note = confirm_money_note;
    }
    showMask('正在提交中...', 1);
    $.post(
      "{AnUrl('order/admin/confirm_pay')}",
      params,
      function (data){
        if (data.info != 'ok') {
          showMsg(data.info);
        }
        location.href = location.href;
      },
      'json'
    );
  });

  // 单个订单删除
  $(".js_deleteOrder,.js_changeStatus").live('click',function(e){
    e.preventDefault();
    e.stopPropagation();
    var selectId = $(this).closest("tr").attr("id");
    var roleId = $(this).closest("tr").data("id");
    if (!selectId) {
      alert('请选择要操作记录');
    }

    var clickObj = $(this);
    var url = clickObj.attr("href");
    var cardListBox = clickObj.closest('.cardListBox');
    var lines = $(this).parent().attr('rowspan');
    var notice = {if $status == 1}'确定要删除此订单吗？'{else}'确定执行此操作吗?'{/if};
    showConfirm(notice, 1, function(){
      $.post(url, {  'id':selectId }, function(json){
        if (json.info != 'ok') {
          alert(json.info);
        } else {
          clickObj.closest("tr").fadeOut(function(){
            if (lines) {
              for (var i = 1; i < lines; i++) {
                $(this).next().remove();
              }
            };
            $(this).remove();
            interLineColor();
            {if $status == 1}
            showMsg('删除成功!被删除订单可在回收站还原.', 1);
            {/if}
            if (cardListBox) {
              var trNum = cardListBox.find('.deleteOne').length;
              var level_total = cardListBox.attr('data-level_total');
              consoleLog(trNum);
              consoleLog(level_total);
              if (trNum < level_total) {
                $('.addCard').show();
              }
            }

            location.href = location.href;
          });
        }
      }, 'json');
    });
    return false;
  });

//单个订单删除
  $(".js_finishStoreOrder").live('click',function(e){
    e.preventDefault();
    e.stopPropagation();
    alert(2);
    var selectId = $(this).closest("tr").attr("id");
    var roleId = $(this).closest("tr").data("id");
    if (!selectId) {
      alert('请选择要操作记录');
    }

    var clickObj = $(this);
    var url = clickObj.attr("href");
    var cardListBox = clickObj.closest('.cardListBox');
    var lines = $(this).parent().attr('rowspan');
    var notice = '确定执行此操作吗?';
    showConfirm(notice, 1, function(){
      $.post(url, {  'id':selectId }, function(json){
        if (json.info != 'ok') {
          alert(json.info);
        } else {
            showMsg('操作成功!');

            location.href = location.href;
        }
      }, 'json');
    });
    return false;
  });



  // added by ninghx 2012-07-31 将页面中的时间插件转移到公用的js中
/*   $('#js_confirm_money_time').datepicker({
    dateFormat: 'yy-mm-dd',
    showButtonPanel: true,
    yearRange: '1900:'+new Date().getFullYear(),
    changeYear:true,
    changeMonth:true,
    maxDate: new Date(),
    yearSuffix: ''
  }); */

  //取消订单事件
  $('.js_cancelOrderBtn').click(function(){
    var order_id = $(this).closest('tr').data('id');
    showConfirmDiv($('.js_cancelOrderDiv'), order_id);
  });

  //同意取消订单操作
  $('#js_cancelOrderAllow').click(function(){
    var order_reason = $.trim($('.js_cancelOrderReason').val());
    var id = $('.js_cancelOrderDiv').data('id');

    if (!order_reason || order_reason == '') {
      showMsg('请填写取消订单的理由');
      return false;
    }

    showMask('正在提交中...', 1);

    $.post(
      "{AnUrl('order/admin/cancel_order')}",
      { order_reason:order_reason, id:id },
      function (data){
        if (data.info != 'ok') {
          showMsg(data.info);
        }
        location.href = location.href;
      },
      'json'
    );
  });

  function showConfirmDiv(obj, id) {
    var width = $(window).width();
    var height = $(window).height();
    var divWidth = parseInt(obj.css('width'));
    var divHeight = parseInt(obj.css('height'));
    var leftWidth = (width - divWidth) / 2;
    var topHeight = $(window).scrollTop()+(height - divHeight) / 2;
    obj.css({ left:leftWidth+'px', top:topHeight+'px' }).attr('data-id', id).show();
  }
});
</script>
<div class="float-confirm js_recommendDiv" style="z-index: 20000;display: none; width:auto;">
  <div class="float-confirm-con">
    <p style="font-size:18px;color:#23a18b;">输入物流编号发货</p>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
    <div style="width:500px;height:auto;margin-bottom:15px;">
      <table style="line-height:50px;" class="js_expressTable">
        <tr>
          <td><span style="color:red;">*</span>物流公司：</td>
          <td style="min-width:400px;">
            {*<select class="js_express_code">
              <option value="0">请选物流递公司</option>
              {foreach $express_list as $v}
              <option value="{$v.id}">{$v.title}</option>
              {/foreach}
            </select>*}
            <input type="text" name="express_name" class="js_express_name">
          </td>
        </tr>
        <tr>
          <td><span style="color:red;">*</span>物流编号：</td>
          <td style="min-width:400px;">
            <input type="text" name="express_no" class="js_express_no">
          </td>
        </tr>
        <tr>
          <td>备注：</td>
          <td style="min-width:400px;">
            <textarea name="express_note" class="add-f-area textarea_box js_express_note"></textarea>
          </td>
        </tr>
      </table>
    </div>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
    <div class="float-confirm-btns" style="padding-bottom:30px;">
      <a id="js_allow" class="btn btn-success btn-sm left" href="javascript:void(0);">确定</a>
      <a class="btn btn-default btn-sm left js_cancel" href="javascript:void(0);">取消</a>
    </div>
  </div>
</div>
<div class="float-confirm js_confirm_moneyDiv" style="z-index: 20000;display: none; width:auto;">
  <div class="float-confirm-con">
    <p style="font-size:18px;color:#23a18b;">输入收款备注</p>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
    <div style="width:500px;height:auto;margin-bottom:15px;">
      <table style="line-height:50px;" class="js_expressTable">
      <tr>
          <td><span style="color:red;">*</span>收款人：</td>
          <td style="min-width:400px;">
            <input type="text" class="search-f-ipt1 js_confirm_money_name" name="" value="">
          </td>
        </tr>
         <tr>
          <td><span style="color:red;">*</span>收款时间：</td>
          <td style="min-width:400px;">
             <input type="text" class="search-f-ipt1 js_confirm_money_time" id="js_confirm_money_time" name=""   value="">
          </td>
        </tr>
        <tr>
          <td>备注：</td>
          <td style="min-width:400px;">
            <textarea name="confirm_money_note" class="add-f-area textarea_box js_confirm_money_note"></textarea>
          </td>
        </tr>
      </table>
    </div>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
    <div class="float-confirm-btns" style="padding-bottom:30px;">
      <a id="js_confirm_moneyAllow" class="btn btn-success btn-sm left" href="javascript:void(0);">确定</a>
      <a class="btn btn-default btn-sm left js_cancel" href="javascript:void(0);">取消</a>
    </div>
  </div>
</div>
<div class="float-confirm js_cancelOrderDiv" style="z-index: 20000;display: none; width:auto;">
  <div class="float-confirm-con">
    <p style="font-size:18px;color:#23a18b;">取消订单理由</p>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
    <div style="width:500px;height:auto;margin-bottom:15px;">
      <table style="line-height:50px;" class="js_expressTable">
        <tr>
          <td>理由：</td>
          <td style="min-width:400px;">
            <textarea name="reason" class="add-f-area textarea_box js_cancelOrderReason"></textarea>
          </td>
        </tr>
      </table>
    </div>
    <div style="width:auto;height:1px;background:#CCC;margin-bottom:20px;"></div>
    <div class="float-confirm-btns" style="padding-bottom:30px;">
      <a id="js_cancelOrderAllow" class="btn btn-success btn-sm left" href="javascript:void(0);">确定</a>
      <a class="btn btn-default btn-sm left js_cancel" href="javascript:void(0);">取消</a>
    </div>
  </div>
</div>
<div class="float-bg" style="z-index: 19999; display: none"></div>
{include_core file="module/order_delivery_verify.html"}
{include_core file="admin/lib/footer.html"}
{include_core file="module/order_export.html"}
